import { isVue2, isVue3, version } from "vue-demi";
import Designer from "./App.vue";
import widgets from "@/components/widgets/index";
import * as VueDemi from "vue-demi";
console.log(VueDemi, VueDemi.version);

// import lodop from "./libs/lodop/index.js";
import vptd from "./store/index";

const vueUrl = new URL("vue", import.meta.url);
console.log("Vue 模块 URL:", vueUrl.href);
const vueDemiUrl = new URL("vue-demi", import.meta.url);
console.log("VueDemi 模块 URL:", vueDemiUrl.href);

const install = (appOrVue) => {
  console.log(isVue2, isVue3, version, appOrVue.version);
  console.log("Running in", isVue2 ? "Vue 2" : "Vue 3", "environment");
  const isV2 = appOrVue.version.startsWith("2");
  if (isV2) {
    const Vue = appOrVue;
    Vue.component("weighbill-designer", Designer);
    // Vue.prototype.$lodop = lodop;
    Vue.prototype.$vptd = vptd;
  } else {
    const app = appOrVue;
    app.component("weighbill-designer", Designer);
    // app.config.globalProperties.$lodop = lodop;
    app.config.globalProperties.$vptd = vptd;
  }
  appOrVue.use(widgets);
};

// 自动安装（如果是直接通过 <script> 引入）
if (typeof window !== "undefined" && window.Vue) {
  install(isVue2 ? window.Vue : createApp());
}

export { Designer, install };
export default {
  install,
};
